package com.okcl.easychat.config;

import com.okcl.easychat.handler.WsHandler;
import com.okcl.easychat.interceptor.WsInterceptor;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

@Configuration
@EnableWebSocket
public class WsConfig implements WebSocketConfigurer {
    @Resource
    private WsHandler wsHandler;
    @Resource
    private WsInterceptor wsInterceptor;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        //注册主要处理器
        registry.addHandler(wsHandler, "/ws").addInterceptors(wsInterceptor).setAllowedOrigins("*");
    }
}
